package Leetcode;

import java.util.HashSet;
import java.util.Set;

public class Leetcode_293 {
    static Set<Integer> seen = new HashSet<Integer>();
    static StringBuffer ans = new StringBuffer();
    static int highest;
    static int k;

    public static String crackSafe(int n, int k) {
        highest = (int) Math.pow(10, n - 1);
        Leetcode_293.k = k;
        dfs(0);
        ans.append("0".repeat(Math.max(0, n - 1)));
        return ans.toString();
    }

    public static void dfs(int node) {
        for (int x = 0; x < k; ++x) {
            int nei = node * 10 + x;
            if (!seen.contains(nei)) {
                seen.add(nei);
                dfs(nei % highest);
                ans.append(x);
            }
        }
    }

    public static void main(String[] args) {
        int n = 1, k = 2;
        System.out.println(crackSafe(n,k));
    }
}
